home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / swtools / mipsABI / examples / sup / supcparse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  5.7 KB  |  232 lines

  1. /*
  2.  * Copyright (c) 1992 Carnegie Mellon University
  3.  * All Rights Reserved.
  4.  * 
  5.  * Permission to use, copy, modify and distribute this software and its
  6.  * documentation is hereby granted, provided that both the copyright
  7.  * notice and this permission notice appear in all copies of the
  8.  * software, derivative works or modified versions, and any portions
  9.  * thereof, and that both notices appear in supporting documentation.
  10.  *
  11.  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  12.  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  13.  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  14.  *
  15.  * Carnegie Mellon requests users of this software to return to
  16.  *
  17.  *  Software Distribution Coordinator  or  Software_Distribution@CS.CMU.EDU
  18.  *  School of Computer Science
  19.  *  Carnegie Mellon University
  20.  *  Pittsburgh PA 15213-3890
  21.  *
  22.  * any improvements or extensions that they make and grant Carnegie Mellon
  23.  * the rights to redistribute these changes.
  24.  */
  25. /*
  26.  * sup collection parsing routines
  27.  **********************************************************************
  28.  * HISTORY
  29.  *
  30.  * 7-July-93  Nate Williams at Montana State University
  31.  *    Modified SUP to use gzip based compression when sending files
  32.  *    across the network to save BandWidth
  33.  *
  34.  * $Log: supcparse.c,v $
  35.  * Revision 1.2  1993/08/04  17:46:20  brezak
  36.  * Changes from nate for gzip'ed sup
  37.  *
  38.  * Revision 1.1.1.1  1993/05/21  14:52:18  cgd
  39.  * initial import of CMU's SUP to NetBSD
  40.  *
  41.  * Revision 1.6  92/08/11  12:07:38  mrt
  42.  *     Added use-rel-suffix option corresponding to -u switch.
  43.  *     [92/07/26            mrt]
  44.  * 
  45.  * Revision 1.5  92/02/08  18:24:19  mja
  46.  *     Added "keep" supfile option, corresponding to -k switch.
  47.  *     [92/01/17            vdelvecc]
  48.  * 
  49.  * Revision 1.4  91/05/16  14:49:50  ern
  50.  *     Change default timeout from none to 3 hours so we don't accumalute 
  51.  *     processes running sups to dead hosts especially for users.
  52.  *     [91/05/16  14:49:21  ern]
  53.  * 
  54.  *
  55.  * 10-Feb-88  Glenn Marcy (gm0w) at Carnegie-Mellon University
  56.  *    Added timeout to backoff.
  57.  *
  58.  * 28-Jun-87  Glenn Marcy (gm0w) at Carnegie-Mellon University
  59.  *    Added code for "release" support.  Removed obsolete options.
  60.  *
  61.  * 25-May-87  Doug Philips (dwp) at Carnegie-Mellon University
  62.  *    Split off from sup.c
  63.  *
  64.  **********************************************************************
  65.  */
  66.  
  67. #include "supcdefs.h"
  68.  
  69.  
  70. #ifdef    lint
  71. static char _argbreak;
  72. #else
  73. extern char _argbreak;            /* break character from nxtarg */
  74. #endif
  75.  
  76. typedef enum {                /* supfile options */
  77.     OHOST, OBASE, OHOSTBASE, OPREFIX, ORELEASE,
  78.     ONOTIFY, OLOGIN, OPASSWORD, OCRYPT,
  79.     OBACKUP, ODELETE, OEXECUTE, OOLD, OTIMEOUT, OKEEP, OURELSUF,
  80.     OCOMPRESS
  81. } OPTION;
  82.  
  83. struct option {
  84.     char *op_name;
  85.     OPTION op_enum;
  86. } options[] = {
  87.     "host",        OHOST,
  88.     "base",        OBASE,
  89.     "hostbase",    OHOSTBASE,
  90.     "prefix",    OPREFIX,
  91.     "release",    ORELEASE,
  92.     "notify",    ONOTIFY,
  93.     "login",    OLOGIN,
  94.     "password",    OPASSWORD,
  95.     "crypt",    OCRYPT,
  96.     "backup",    OBACKUP,
  97.     "delete",    ODELETE,
  98.     "execute",    OEXECUTE,
  99.     "old",        OOLD,
  100.     "timeout",    OTIMEOUT,
  101.     "keep",        OKEEP,
  102.     "use-rel-suffix", OURELSUF,
  103.      "compress",     OCOMPRESS
  104. };
  105.  
  106. passdelim (ptr,delim)        /* skip over delimiter */
  107. char **ptr,delim;
  108. {
  109.     *ptr = skipover (*ptr, " \t");
  110.     if (_argbreak != delim && **ptr == delim) {
  111.         (*ptr)++;
  112.         *ptr = skipover (*ptr, " \t");
  113.     }
  114. }
  115.  
  116. parsecoll(c,collname,args)
  117. COLLECTION *c;
  118. char *collname,*args;
  119. {
  120.     register char *arg,*p;
  121.     register OPTION option;
  122.     int opno;
  123.  
  124.     c->Cnext = NULL;
  125.     c->Cname = salloc (collname);
  126.     c->Chost = NULL;
  127.     c->Chtree = NULL;
  128.     c->Cbase = NULL;
  129.     c->Chbase = NULL;
  130.     c->Cprefix = NULL;
  131.     c->Crelease = NULL;
  132.     c->Cnotify = NULL;
  133.     c->Clogin = NULL;
  134.     c->Cpswd = NULL;
  135.     c->Ccrypt = NULL;
  136.     c->Ctimeout = 3*60*60;    /* default to 3 hours instead of no timeout */
  137.     c->Cflags = 0;
  138.     c->Cnogood = FALSE;
  139.     c->Clockfd = -1;
  140.     args = skipover (args," \t");
  141.     while (*(arg=nxtarg(&args," \t="))) {
  142.         for (opno = 0; opno < sizeofA(options); opno++)
  143.             if (strcmp (arg,options[opno].op_name) == 0)
  144.                 break;
  145.         if (opno == sizeofA(options)) {
  146.             logerr ("Invalid supfile option %s for collection %s",
  147.                 arg,c->Cname);
  148.             return(-1);
  149.         }
  150.         option = options[opno].op_enum;
  151.         switch (option) {
  152.         case OHOST:
  153.             passdelim (&args,'=');
  154.             do {
  155.                 arg = nxtarg (&args,", \t");
  156.                 (void) Tinsert (&c->Chtree,arg,FALSE);
  157.                 arg = args;
  158.                 p = skipover (args," \t");
  159.                 if (*p++ == ',')  args = p;
  160.             } while (arg != args);
  161.             break;
  162.         case OBASE:
  163.             passdelim (&args,'=');
  164.             arg = nxtarg (&args," \t");
  165.             c->Cbase = salloc (arg);
  166.             break;
  167.         case OHOSTBASE:
  168.             passdelim (&args,'=');
  169.             arg = nxtarg (&args," \t");
  170.             c->Chbase = salloc (arg);
  171.             break;
  172.         case OPREFIX:
  173.             passdelim (&args,'=');
  174.             arg = nxtarg (&args," \t");
  175.             c->Cprefix = salloc (arg);
  176.             break;
  177.         case ORELEASE:
  178.             passdelim (&args,'=');
  179.             arg = nxtarg (&args," \t");
  180.             c->Crelease = salloc (arg);
  181.             break;
  182.         case ONOTIFY:
  183.             passdelim (&args,'=');
  184.             arg = nxtarg (&args," \t");
  185.             c->Cnotify = salloc (arg);
  186.             break;
  187.         case OLOGIN:
  188.             passdelim (&args,'=');
  189.             arg = nxtarg (&args," \t");
  190.             c->Clogin = salloc (arg);
  191.             break;
  192.         case OPASSWORD:
  193.             passdelim (&args,'=');
  194.             arg = nxtarg (&args," \t");
  195.             c->Cpswd = salloc (arg);
  196.             break;
  197.         case OCRYPT:
  198.             passdelim (&args,'=');
  199.             arg = nxtarg (&args," \t");
  200.             c->Ccrypt = salloc (arg);
  201.             break;
  202.         case OBACKUP:
  203.             c->Cflags |= CFBACKUP;
  204.             break;
  205.         case ODELETE:
  206.             c->Cflags |= CFDELETE;
  207.             break;
  208.         case OEXECUTE:
  209.             c->Cflags |= CFEXECUTE;
  210.             break;
  211.         case OOLD:
  212.             c->Cflags |= CFOLD;
  213.             break;
  214.         case OKEEP:
  215.             c->Cflags |= CFKEEP;
  216.             break;
  217.         case OURELSUF:
  218.             c->Cflags |= CFURELSUF;
  219.             break;
  220.         case OCOMPRESS:
  221.             c->Cflags |= CFCOMPRESS;
  222.             break;
  223.         case OTIMEOUT:
  224.             passdelim (&args,'=');
  225.             arg = nxtarg (&args," \t");
  226.             c->Ctimeout = atoi (arg);
  227.             break;
  228.         }
  229.     }
  230.     return(0);
  231. }
  232.